package com.chanceit.ssss.adapters;

import org.gl.utils.lg;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.chanceit.ssss.activity.R;
import com.chanceit.ssss.fragments.BaseFragment;
import com.chanceit.ssss.fragments.CarerInShopListFragment;
import com.chanceit.ssss.fragments.CarerListFragment;
import com.chanceit.ssss.fragments.OrderCarerListFragment;

public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
	Activity context;
	String tabs[] = new String[3];
	Fragment[] fagments = new Fragment[tabs.length];

	public SectionsPagerAdapter(FragmentManager fm, Activity context) {
		super(fm);
		this.context = context;
		tabs = new String[] {
				context.getString(R.string.tab_title_order_carer),
				context.getString(R.string.tab_title_todo_carer)};
//		tabs = new String[] {
//				context.getString(R.string.tab_title_order_carer),
//				context.getString(R.string.tab_title_todo_carer),
//				context.getString(R.string.tab_title_all_carer) };
	}

	@Override
	public Fragment getItem(int position) {
		// getItem is called to instantiate the fragment for the given page.
		// Return a DummySectionFragment (defined as a static inner class
		// below) with the page number as its lone argument.
		// Fragment fragment = new HjFragment();
		// Bundle args = new Bundle();
		// args.putInt("no", position + 1);
		// fragment.setArguments(args);
		Fragment fragment = fagments[position];
		if (fragment == null) {
			switch (position) {
			case 1:
				fragment = new CarerInShopListFragment();
				fagments[position] = fragment;
				break;
			case 2:
				fragment = new CarerListFragment();
				fagments[position] = fragment;
				break;
			case 0:
				fragment = new OrderCarerListFragment();
				fagments[position] = fragment;
				break;
			default:
				fragment = new CarerListFragment();
				fagments[position] = fragment;
				break;
			}
		}
		return fragment;
	}

	@Override
	public int getCount() {
		// Show 3 total pages.
		return tabs.length;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return tabs[position];
	}
	String TAG = "SectionPagerAdpater";
	public void sendMessage(int postion){
		if (fagments[postion]!=null&&fagments[postion] instanceof BaseFragment) {
			((BaseFragment) fagments[postion]).receiveMessage(null);
		}else{
			lg.e(TAG, "Exception,the fragment is null,or not BaseFragment ,so it can not receive message,");
		}
	}
}